<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ page import="java.sql.*,java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DB_URL = "jdbc:mysql://localhost:3306/sims";
String USER = "root";
String PASS = "123456";

Class.forName(JDBC_DRIVER);
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);

String name = request.getParameter("name");  
String gender = request.getParameter("gender");   
String phone = request.getParameter("phone");   
String id = request.getParameter("id"); 
String sql = "update student set name=?,gender=?,phone=? where id=?";
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {   
    pstmt.setString(1, name);  
    pstmt.setString(2, gender);      
    pstmt.setString(3, phone);  
    pstmt.setString(4,id);
int rowsAffected = pstmt.executeUpdate();  
if (rowsAffected > 0) {  
	out.println("<script>alert('修改成功！');window.location.href='index.jsp';</script>"); 
} else {  
	out.println("<script>alert('修改失败！');window.history.back();</script>"); 
} 
} catch (SQLException e) {   
e.printStackTrace();
}
%>
</body>
</html>